package com.boang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.boang.domain.Cla;
import com.boang.service.ClaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/*
  @author: 13813
  @date: 2024/8/7 10:06
*/
@RestController
@RequestMapping("/cla")
public class ClaController {

    @Autowired
    private ClaService claService;

    @RequestMapping("/getClaList")
    public List<Cla> getClaList() {
        return claService.list();
    }

    @RequestMapping("/addCla")
    public boolean addCla(@RequestBody Cla cla) {
        return claService.save(cla);
    }

    @RequestMapping("/updateCla")
    public boolean updateCla(@RequestBody Cla cla) {
        return claService.updateById(cla);
    }

    @RequestMapping("/deleteCla")
    public boolean deleteCla(String id) {
        return claService.removeById(id);
    }

    @RequestMapping("/getCla")
    public Cla getCla(@RequestBody Cla cla) {
        //封装查询条件  select * from cla where id = 1
        LambdaQueryWrapper<Cla> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Cla::getId, cla.getId());
        return claService.getOne(lambdaQueryWrapper);
    }

    @RequestMapping("/page")
    public Page<Cla> page(int current, int size) {
//        Page<Cla> page = new Page<>(1, 5);
        Page<Cla> page = new Page<>(current, size);
        return claService.page(page);
    }
}
